import { _decorator } from 'cc';
import { FairyScriptView } from 'db://assets/pkg-export/fairygui/FairyGUIView';
import { HomeController } from 'db://assets/app-builtin/app-controller/HomeController';
import { app } from 'db://assets/app/app';
import * as i18n from 'db://i18n/LanguageData';
import { UIPanel } from 'db://fairygui-xforge/UIPanel';
import { registerScriptUI } from 'db://app/base/BaseView';
const { ccclass, property } = _decorator;
@registerScriptUI("Paper", "fgui-package1")
@ccclass('PaperAllTest')
export class PopTest extends FairyScriptView<UI_Package1_TestPaper, HomeController, any>("Package1", "TestPaper", HomeController) {

    protected onUIInit(content: UI_Package1_TestPaper): void {
        content.m_btnClose.onClick(this.onBtnCloseClick, this);
        content.m_btnJump.onClick(this.onBtnJumpClick, this);
        content.m_btnPop.onClick(this.onBtnPopClick, this);
        content.m_btnPop2.onClick(this.onBtnPop2Click, this);
        content.m_btnSwitch.onClick(this.onBtnSwitchClick, this);
        content.m_btnClose.i18nText = "test.close";
        content.m_btnJump.i18nText = "test.jump";
        content.m_btnPop.i18nText = "test.dialog";
        content.m_btnPop2.i18nText = "test.dilaog2";
        content.m_btnSwitch.i18nText = "test.zhName";
        content.m_btnSwitch.i18nSelectedTitle = "test.enName";
    }

    // 界面打开时的相关逻辑写在这(onShow可被多次调用-它与onHide不成对)
    onShow(params: any) {
        super.onShow(params)
        this.controller.refresh("test")
    }

    // 界面关闭时的相关逻辑写在这(已经关闭的界面不会触发onHide)
    onHide(result: undefined) {
        // app.manager.ui.show<PaperHomeTest>({name: 'PaperHomeTest', onHide:(result) => { 接收到return的数据，并且有类型提示 }})
        return result;
    }

    private onBtnCloseClick() {
        this.hide();
    }

    private onBtnPopClick(): void {
        app.manager.ui.show({
            name: 'PopTip',
            data: this.viewName
        });
    }

    private onBtnPop2Click(): void {
        console.log('onBtnPop2Click');
    }

    private onBtnJumpClick() {
        app.manager.ui.show({
            name: 'PageGame'
        });
    }

    private onBtnSwitchClick() {
        i18n.init(this.Content.m_btnSwitch.selected ? 'en' : 'zh');
        UIPanel.UpdateLocalized();
        i18n.updateSceneRenderers();
    }
}


